﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace Nirvana
{
    /// <summary>
    /// 文本曲面圆柱体运动
    /// </summary>
    [AddComponentMenu("Nirvana/UI/Effects/Cylinder Text")]
    [RequireComponent(typeof(Text))]
    public class UICylinderText : BaseMeshEffect
    {
        [SerializeField]
        private float Radius = 220f;

        public override void ModifyMesh(VertexHelper vh)
        {
            if (!this.IsActive() || vh.currentVertCount <= 0)
            {
                return;
            }

            for (int i = 0; i < vh.currentVertCount; i++)
            {
                UIVertex vertex = default(UIVertex);
                vh.PopulateUIVertex(ref vertex, i);//返回当前顶点数据
                float x = vertex.position.x;
                vertex.position.z = -this.Radius * Mathf.Cos(x / this.Radius);
                vertex.position.x = this.Radius * Mathf.Sin(x / this.Radius);
                vh.SetUIVertex(vertex,i);
            }
        }

        protected override void Awake()
        {
            base.Awake();
            this.OnRectTransformDimensionsChange();
        }

        protected override void OnEnable()
        {
            base.OnEnable();
            this.OnRectTransformDimensionsChange();
        }
    }
}
